<?php
class Model_Cate extends Model{

    //首页数据
    public function getPostInfo($type,$offset=0,$pageSize=20){

        $data=DB::select(array('postid','id'),'title','introduction','description','tags','images','url','price','view','reach','review','created','wish','praiseup','praisedown')
        
        ->from('post')
        
        ->where('isdeleted','=','0')

        ->and_where('type','=',$type)

        ->order_by('sort','desc')
        
        ->order_by('praiseup','desc')

        ->order_by('view','desc')

        ->order_by('wish','desc')

        ->order_by('postid','desc')
        
        ->limit($pageSize)
        
        ->offset($offset)
        
        ->execute()->as_array();

        return $data;

    }

    //post总数
    public function getItems($type){

         $total= DB::select(array(DB::expr('count(1)'), 'total'))

         ->from('post')

        ->where('isdeleted','=','0')

        ->and_where('type','=',$type)

        ->execute()

        ->get("total");

        return $total;

    }

    public function getInfoByUrl($caption){

       $data=DB::select(array('post_typeid','id'),'caption')
        
        ->from('post_type')
        
        ->where('isdeleted','=','0')

        ->and_where('caption','=',$caption)
        
        ->limit(1)

        ->execute()

        ->as_array();

        if(!empty($data)){

          $data=$data[0];

        }

        return $data;
    }
}